
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<script type="text/javascript">
    //$.noConflict();

    $(window).resize(function() {
        $('#grid_waterele').datagrid('resize');
    });

    function clearwatereleForm(){
        $('#watereleForm').form('clear');
    }

    function clearQueryParamZone(){
        $('#queryForm_Waterele').form('clear');
    }

    $(function(){
        $('#ps_id_combox').combobox({
            url:'/Manage/AdminCsdt/get_all_combox',
            valueField:'id',
            textField:'name'
        });
        $('#grid_waterele').datagrid({
            //title:'水表',
            width: '100%',
            //height: 400,
            fit: true,
            nowrap: false,
            striped: true,
            collapsible:false,
            url:'/Manage/AdminCsdtWater/get_all',
            queryParams:{page:1,rows:20},
            method:'get',
            pageNumber:1,
            pageSize:20,
            idField:'id',
            remoteSort: false,
            columns:[[
                {field:'id',title:'序号',width:60,checkbox:true},
                {field:'sta_name',title:'调蓄池名称',width:180,align:'center'},
                {field:'we_name',title:'水表名称',width:100,align:'center'},
                {field:'we_number',title:'水表表号',width:100,align:'center'}
            ]],
            pagination:true,
            rownumbers:true,
            singleSelect:false,
            toolbar: '#grid_waterele_ToolBar',
            onDblClickRow: function(rowIndex, rowData) {
                var selected = $('#grid_waterele').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    editWaterele(rowData.id);
                }else{
                    var rows = $('#grid_waterele').datagrid('getSelections');
                    if(selected){
                        if(selected.id == rowData.id){
                            editWaterele(rowData.id);
                        }else{
                            $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        }
                    }else{
                        editWaterele(rowData.id);
                    }
                }
            },
            onSelect: function(rowIndex, rowData) {
                var now_rows = jQuery('#grid_waterele').datagrid('getSelections');
                if(now_rows.length > 1){
                    $("#btnEditWaterele").linkbutton('disable');
                }
            },
            onUnselect: function(rowIndex, rowData) {
                var now_rows = jQuery('#grid_waterele').datagrid('getSelections');
                if(now_rows.length < 2){
                    $("#btnEditWaterele").linkbutton('enable');
                }
            },
            onLoadSuccess: function(data) {
                $(this).datagrid('resize');
            }
        });

        $('#btnAddWaterele').click(function() {
            clearwatereleForm();
            $("#saveflag_waterele").val("add");
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name'
            });
            $('#watereleDlg').dialog({title:'录入水表信息',modal:true});
            $('#watereleDlg').dialog("open");
        });

        $('#btnEditWaterele').click(function() {
            var selected = $('#grid_waterele').datagrid('getSelected');
            if($('#single').is(":hidden")){
                if (selected) {
                    editWaterele(selected.id);
                }
            }else{
                var rows = $('#grid_waterele').datagrid('getSelections');
                if(rows.length == 1 || rows.length == 0){
                    if (selected) {
                        editWaterele(selected.id);
                    }
                    else{
                        $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                    }
                }else{
                    $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                    singleToggle();
                }
            }
        });
        $('#btnDelWater').click(function() {

            var ids = [];
            var rows = $('#grid_waterele').datagrid('getSelections');
            for ( var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            if ((ids != null) && (ids.length > 0)) {
                $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                    if (r) {

                        $('#batchDelFormWaterele').ajaxSubmit({
                            url:"/Manage/AdminCsdtWater/deleteArray",
                            data:{'ids':ids.join(',')},
                            dataType:'json',
                            success: function(data) {
                                console.log(data);
                                if (data.status==1) {
                                    $('#grid_waterele').datagrid('reload');
                                    $('#grid_waterele').datagrid("unselectAll");
                                    $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                }
                                else $.messager.alert('提示','删除失败！','error');
                            }
                        });

                    }
                });
            }
        });
        $('#btnSearchWaterele').click(function() {
            $('#queryParamZone_waterele').toggle();
            if($('#queryParamZone_waterele').is(":hidden")){
                clearQueryParamZone();
            }
            $('#grid_waterele').datagrid("resize");
        });

        $('#btnQueryWaterele').click(function() {
            var obj = $('#queryForm_Waterele').serializeJson();
            $('#grid_waterele').datagrid('load',obj);
        });

        var model = 'PumpPump';
        table_index_change(model, 'base');

        $('#queryParamZone_waterele').hide();
        $('#single').hide();

        /* WdatePicker({el:'pump_mdate',readOnly:true});
         $dp.hide(); */
    });

    function editWaterele(id) {
        if(id!=""){
            $("#saveflag_waterele").val("update");
        }else{
            clearwatereleForm();
            $("#saveflag_waterele").val("add");
            return;
        }
        $.ajax({url:"/Manage/AdminCsdtWater/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name'
            });
            $('#watereleForm').form('load',{
                "id": json.id,
                'ps_id':json.ps_id,
                "we_number": json.we_number,
                "we_name": json.we_name,
            });
            $('#watereleDlg').dialog({title:'编辑水表信息',modal:true});
            $('#watereleDlg').dialog("open");
            setFormFocus('#watereleForm');
        },error:function(XMLHttpRequest, textStatus, errorThrown)
        {
            relogin(XMLHttpRequest, textStatus, errorThrown);
        }});
    }

    function submitwatereleForm() {
        if ($('#watereleForm').form('validate')) {
            var submitflag = $("#saveflag_waterele").val();
            var url = "";
            console.log(submitflag);
            if (submitflag === "add")
                url = "/Manage/AdminCsdtWater/add";
            if (submitflag === "update")
                url = "/Manage/AdminCsdtWater/edit";
            $('#watereleForm').ajaxSubmit({
                url:url,
                dataType:'json',
                success: function(data) {
                    if (data.status==1) {
                        if (submitflag === "add") $('#grid_waterele').datagrid('load');
                        if (submitflag === "update") $('#grid_waterele').datagrid('reload');
                        $('#watereleDlg').dialog("close");
                        $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                    }
                    else $.messager.alert('提示','操作失败！','error');
                }
            });
        }
    }
</script>
<table id="grid_waterele"></table>
<div id="grid_waterele_ToolBar" style="padding:5px;height:auto">
    <div style="margin-bottom:5px">
        <a id="btnAddWaterele" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
        <a id="btnEditWaterele" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
        <a id="btnDelWater" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <a id="btnSearchWaterele" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
        <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_waterele').datagrid({url:'/Manage/AdminCsdtWater/get_all',queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:20}})">重载</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=/Manage/AdminCsdtWater/import')">导入</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('/Manage/AdminCsdtWater/export')">导出</a>
    </div>
    <div id="queryParamZone_waterele">
        <form id="queryForm_Waterele" method="post" action="">
            <table>
                <tr>
                    <td>调蓄池</td>
                    <td><input id="ps_id_combox" name="ps_id"></td>
                    <td>水表名称</td>
                    <td>
                        <input type="text" name="we_name">
                    </td>
                    <td>水表表号</td>
                    <td>
                        <input type="text" name="we_number">
                    </td>
                    <td><a id="btnQueryWaterele" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                    <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_Waterele').form('clear');">重置</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div id="watereleDlg" class="easyui-dialog" title="" style="width:650px;height:300px;padding:10px" buttons="#dlg-buttons-waterele" closed="true" resizable="true">
    <form id="watereleForm" method="post" action="">
        <input id="saveflag_waterele" name="saveflag_waterele" type="hidden" value="add"/>
        <input type="hidden" name="id" />
        <table border="0">
            <tr>
                <td align="right">调蓄池名称：</td>
                <td>
                    <input id="ps_id_combox_1" name="ps_id" required="true" style="width: 180px;">
                </td>
            </tr>
            <tr>
                <td align="right">水表名称：</td>
                <td>
                    <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="we_name" required="true"></input>
                </td>
                <td align="right">水表编号：</td>
                <td>
                    <input class="easyui-textbox" type="text" name="we_number" required="true" style="width: 140px;"></input>
                </td>
                </td>
            </tr>


        </table>
    </form>
</div>
<div id="dlg-buttons-waterele" style="text-align: center;">
    <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitwatereleForm();">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:editWaterele($('#pumpstation_id').val());">重置</a>
</div>
<form id="batchDelFormWaterele" method="post">
    <input id="ids" type="hidden" name="ids"/>
</form>